<template>
  <basic-container>
    <div>
      <EventLogSearch
        @searchClick="
          (v) => {
            (queryForm = v), getList();
          }
        "
      >
      </EventLogSearch>
    </div>

    <avue-crud
      :option="eventLogOption"
      :data="data"
      :table-loading="loading"
      :page.sync="page"
      @current-change="currentChange"
      @size-change="sizeChange"
      @selection-change="(v) => (selection = v)"
      ref="curd"
    >
      <template slot="triggerMsg" slot-scope="{ row }">
        <div v-if="row.triggerMsg">
          <el-tooltip placement="top">
            <div slot="content" v-html="row.triggerMsg"></div>
            <el-button type="text">查看</el-button>
          </el-tooltip>
        </div>
        <div v-else>无</div>
      </template>
      <template slot="handleMsg" slot-scope="{ row }">
        <div v-if="row.handleMsg">
          <el-tooltip placement="top">
            <div slot="content" v-html="row.handleMsg"></div>
            <el-button type="text">查看</el-button>
          </el-tooltip>
        </div>
        <div v-else>无</div>
      </template>
      <template slot="triggerCode" slot-scope="{ row }">
        <div v-if="row.triggerCode === 200">
          <el-button type="text">成功</el-button>
        </div>
        <div v-else>
          <el-button type="text" style="color: red">失败</el-button>
        </div>
      </template>
      <template slot="handleCode" slot-scope="{ row }">
        <div v-if="row.handleCode === 200">
          <el-button type="text">成功</el-button>
        </div>
        <div v-else>
          <el-button type="text" style="color: red">失败</el-button>
        </div>
      </template>
    </avue-crud>
    
  </basic-container>
</template>

<script>
import EventLogSearch from "./eventLogSearch.vue";
import * as taskManageApi from "@/api/taskManage/taskManage";
import * as api from "@/api/eventManage/index";

export default {
  name: "dispatchLog",
  components: {
    EventLogSearch,
  },
  inject: ["eventLogOption"],

  data() {
    return {
      data: [],
      queryForm: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 1,
      },
      visible: false,
      loading: false,
    };
  },
  methods: {
    // 向抽屉中添加tab页 根据 oid 去重
    addToTabsList(title, row, component, type) {
      let ids = this.tabsList.map((item) => item.row[this.idKey]);
      if (!ids.includes(row[this.idKey])) {
        this.tabsList.push({ title, row, component, type });
      }
      this.visible = true;
    },
    getList() {
      const params = {};
      for (let key in this.queryForm) {
        if (this.queryForm[key]) {
          params[key] = this.queryForm[key];
        }
      }
      if(this.queryForm.filterTime){
        const newArr2 = this.queryForm.filterTime.map((v,index)=>{
          if(index === 0){
            return v
          }else{
            const arr1= v.split(' ');
            return arr1[0] +' 23:59:59'
          }

        })
        params.filterTime = newArr2.join(' - ')
      }
      api
        .getLogList({
          ...params,
          start: this.page.currentPage,
          length: this.page.pageSize,
        })
        .then((res) => {
          this.data = res.data.data;
          this.page.total = res.data.recordsTotal;
        });
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.getList();
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.getList();
    },
    // 删除
    delRow(data) {
      this.$confirm("是否删除？").then(() => {
        taskManageApi.delMethod({ id: data.id }).then(() => {
          this.$message.success("删除成功");
          this.getList();
        });
      });
    },
  },
  mounted() {
    this.getList();
  },
};
</script>
